/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package queenb.web.permission.controller;



import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.Q400;
import queenb.web.controller.QueenbController;
import queenb.web.permission.store.Q400Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class Q400Controller extends QueenbController{

    private int PQ400;
    private String QV401;
    private String QV402;
    private int FQ300 ;
    private List<SelectItem> cmbQ300 = new ArrayList<SelectItem>();
    private List<Q400> list = new ArrayList<Q400>();
    ComboboxUtil cmb = new ComboboxUtil();


    public Q400Controller()
    {
        getKapiMenu().setAdmin(true);
        getKapiMenu().setMainmenu2("m224");
        Object id = getRequest().getParameter("fq300");
        if(id != null){
             FQ300 = Integer.parseInt(id.toString());

        }
        Object id2 = getRequest().getParameter("fq400");
        if(id2 != null){
             PQ400 = Integer.parseInt(id2.toString());

        }
        Object action = getRequest().getParameter("action");
        if(action != null){
            getData(PQ400 ,FQ300);
            System.out.println("----------->" + FQ300 +""+ PQ400 +"-"+ list.size());
            if(list.size() > 0){
                QV401 = list.get(0).getQv401();
                QV402 = list.get(0).getQv402();
            }
        }

    }
    public void save(){
        System.out.println("---change+++++++++++++" + QV401 + QV402 + FQ300 +"----"+ PQ400);

        Q400Store store = new Q400Store();
        try{
           store.updateQ400(PQ400, QV401, QV402, FQ300, getLogin().getModule(), getLogin().getUserName());
           showGlobalReport(true, getResourceString("datasavesuccessful"));
        }catch( Exception ex){
            showGlobalReport(true, getResourceString("datasuccessfail"));
        }
        sendRedirectUrlTab("q300.jsp?fq300="+FQ300+"&linkq300="+Util.convertMD5(getRequest().getRequestURI()));
    }
    public void change(ActionEvent ac) {
        //getData(FQ300 , 0);
        System.out.println("---change+++++++++++++" + FQ300);
    }
    public void getData(int pn400, int fq300){
        Q400Store store = new Q400Store();
        try{
           list = store.ListOfTabQ400(getLogin().getModule(),pn400, fq300, getLogin().getUserName()) ;
        }catch( Exception ex){

        }
    }

    /**
     * @return the list
     */
    public List<Q400> getList() {

           getData(0,FQ300);

        return list;
    }

    /**
     * @param list the list to set
     */
    public void setList(List<Q400> list) {
        this.list = list;
    }

    /**
     * @return the PQ400
     */
    public int getPQ400() {
        return PQ400;
    }

    /**
     * @param PQ400 the PQ400 to set
     */
    public void setPQ400(int PQ400) {
        this.PQ400 = PQ400;
    }

    /**
     * @return the QV401
     */
    public String getQV401() {
        return QV401;
    }

    /**
     * @param QV401 the QV401 to set
     */
    public void setQV401(String QV401) {
        this.QV401 = QV401;
    }

    /**
     * @return the QV402
     */
    public String getQV402() {
        return QV402;
    }

    /**
     * @param QV402 the QV402 to set
     */
    public void setQV402(String QV402) {
        this.QV402 = QV402;
    }

    /**
     * @return the FQ300
     */
    public int getFQ300() {
        return FQ300;
    }

    /**
     * @param FQ300 the FQ300 to set
     */
    public void setFQ300(int FQ300) {
        this.FQ300 = FQ300;
    }

    /**
     * @return the cmbQ300
     */
    public List<SelectItem> getCmbQ300() {
        cmbQ300 = cmb.getListCombQ300();
        if(cmbQ300.size() > 0){
            FQ300 = Integer.parseInt(cmbQ300.get(0).getValue().toString() );
        }
        return cmbQ300;
    }

    /**
     * @param cmbQ300 the cmbQ300 to set
     */
    public void setCmbQ300(List<SelectItem> cmbQ300) {
        this.cmbQ300 = cmbQ300;
    }




}

